package com.lzdongrui.web.controller.system;

import java.util.List;

import com.lzdongrui.common.utils.SecurityUtils;
import com.lzdongrui.system.domain.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzdongrui.common.annotation.Log;
import com.lzdongrui.common.core.controller.BaseController;
import com.lzdongrui.common.core.domain.AjaxResult;
import com.lzdongrui.common.core.page.TableDataInfo;
import com.lzdongrui.common.enums.BusinessType;
import com.lzdongrui.system.domain.SysNotice;
import com.lzdongrui.system.service.ISysNoticeService;

/**
 * 公告 信息操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController
{
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNotice notice)
    {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable Long noticeId)
    {
        return success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysNotice notice)
    {
        notice.setCreateBy(getUsername());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysNotice notice)
    {
        notice.setUpdateBy(getUsername());
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds)
    {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }


    /**
     * 给教师发送审核通知
     */
    @PreAuthorize("@ss.hasPermi('system:notice:teacherAuditAdd')")
    @Log(title = "给教师发送审核通知", businessType = BusinessType.INSERT)
    @PostMapping("/teacherAuditAdd")
    public AjaxResult teacherAuditNoticeAdd(Notification notification)
    {
        return toAjax(noticeService.teacherAuditNoticeAdd(notification));
    }


    /**
     * 给学生发送假期审核通过通知
     */
    @PreAuthorize("@ss.hasPermi('system:notice:studentLeavePassAdd')")
    @Log(title = "给学生发送假期审核通过通知", businessType = BusinessType.INSERT)
    @PostMapping("/studentLeavePassAdd")
    public AjaxResult studentLeavePassAdd(Notification notification)
    {
        return toAjax(noticeService.studentLeavePassAdd(notification));
    }

    /**
     * 给学生发送假期审核不通过通知
     */
    @PreAuthorize("@ss.hasPermi('system:notice:studentLeaveNotpassAdd')")
    @Log(title = "给学生发送假期审核不通过通知", businessType = BusinessType.INSERT)
        @PostMapping("/studentLeaveNotpassAdd")
    public AjaxResult studentLeaveNotpassAdd(Notification notification)
    {
        return toAjax(noticeService.studentLeaveNotpassAdd(notification));
    }

    /**
     * 提醒学生假期结束通知
     */
    @PreAuthorize("@ss.hasPermi('system:notice:studentEndLeave')")
    @Log(title = "提醒学生假期结束通知", businessType = BusinessType.INSERT)
    @PostMapping("/studentEndLeave")
    public AjaxResult studentEndLeave(Notification notification)
    {
        return toAjax(noticeService.studentEndLeave(notification));
    }

    /**
     * 提醒教师学生已返校
     */
    @PreAuthorize("@ss.hasPermi('system:notice:studentEeturnSchool')")
    @Log(title = "提醒教师学生已返校", businessType = BusinessType.INSERT)
    @PostMapping("/studentEeturnSchool")
    public AjaxResult studentEeturnSchool(Notification notification)
    {
        return toAjax(noticeService.studentEeturnSchool(notification));
    }

    /**
     * 获取通知（管理端用）
     */
    @PreAuthorize("@ss.hasPermi('system:notice:all-list-admin')")
    @GetMapping("/all-list-admin")
    public TableDataInfo notificationAllList(Notification notification)
    {
        startPage();
        notification.setViewerUserId(getUserId());
        List<Notification> list = noticeService.notificationAllList(notification);
        return getDataTable(list);
    }

    /**
     * 确认读取通知
     */
    @PreAuthorize("@ss.hasPermi('system:notice:sure-notice')")
    @Log(title = "确认读取通知", businessType = BusinessType.UPDATE)
    @PutMapping("/{Ids}")
    public AjaxResult acknowledgeReceipt(@PathVariable Long Ids)
    {
        Ids = getUserId();
        return toAjax(noticeService.acknowledgeReceipt(Ids));
    }

}
